package com.duoketech.service.unit;

import com.duoketech.service.AbstractService;
import com.duoketech.model.unit.Unit;
import com.duoketech.exception.ValidateException;
import com.duoketech.utils.search.QueryConstructor;
import com.duoketech.utils.validator.Validator;
import com.duoketech.utils.validator.rules.string.StringLengthBetween;
import com.duoketech.utils.validator.rules.string.StringMustBeRequired;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Model;

public class UnitService extends AbstractService{
    public static UnitService ME = new UnitService();

    @Override
    public void validatorUpdate(Model<?> model, Kv kv) throws ValidateException {
        validatorAdd(model,kv);
    }

    @Override
    public void validatorAdd(Model<?> model, Kv kv) throws ValidateException {

        Validator validator = new Validator();
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.ID),"项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.ID),"项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.NAME),"名称项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.NAME),"名称项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.CHARGER),"负责人项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.CHARGER),"负责人项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.MOBILE),"联系电话项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.MOBILE),"联系电话项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.ADDRESS),"地址信息项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.ADDRESS),"地址信息项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.DESC),"简介项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.DESC),"简介项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.CREATE_TIME),"创建时间项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.CREATE_TIME),"创建时间项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.MODIFY_TIME),"更新时间项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.MODIFY_TIME),"更新时间项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Unit.STATUS),"状态项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Unit.STATUS),"状态项字符必须为1-50个字符",1,50));
        validator.excute();

    }

    @Override
    public void beforAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public String tableName() {
        return Unit.dao.tableName();
    }

    @Override
    public void builderSQLExpected(Model<?> model, QueryConstructor queryConstruct, Kv kv) {

    }
}